﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace IFPRJ.EF.Components.SkinEgine
{
    /// <summary>
    /// 针对 HttpContextBase 的扩展。在 cookie 中存取皮肤名称。
    /// </summary>
    public static class SkinCookieExtension
    {
        private static readonly string _cookieName = "select_skin_name";
        private static readonly string _defaultSkin = "default";

        // 获取当前皮肤名称
        public static string GetSkinName(this HttpContextBase context)
        {
            HttpCookie cookie = context.Request.Cookies[_cookieName];
            if (cookie != null)
                return cookie.Value;
            return _defaultSkin;
        }

        // 设置当前皮肤名称
        public static void SetSkinName(this HttpContextBase context, string name)
        {
            if (context.Response.Cookies.AllKeys.Contains(_cookieName))
                context.Response.Cookies.Remove(_cookieName);
            HttpCookie cookie = new HttpCookie(_cookieName, name);
            context.Response.Cookies.Add(cookie);
        }
    }
}
